package com.ocom.srvpamh.controller;


import com.ocom.common.constant.AiotUrl;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;

import com.ocom.srvpamh.service.AccessDeviceService;
import com.ocom.srvpamh.vo.SetDeviceStatusBySaasVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AccessDeviceController {
    private final Logger log = LoggerFactory.getLogger(AccessDeviceController.class);

    @Autowired
    private AccessDeviceService accessDeviceService;


    //1.1. SaaS平台激活设备（SetDeviceActBySaas）
    @PostMapping(AiotUrl.Url_SetDeviceActBySaas)
    public Result SetDeviceActBySaas(@Validated  @RequestBody SetDeviceStatusBySaasVo setDeviceStatusBySaasVo){
        if (setDeviceStatusBySaasVo.getDeviceNo().isEmpty() ){
            log.error("设备编号为空");
            return ResultUtil.error(ResultEnum.Err_203,"设备编号为空");
        }
        if ( setDeviceStatusBySaasVo.getSaasNo().isEmpty()){
            log.error("SaaS平台编号为空");
            return ResultUtil.error(ResultEnum.Err_203,"SaaS平台编号");
        }
        if (setDeviceStatusBySaasVo.getComId() == null){
            log.error("单位编号为空");
            return ResultUtil.error(ResultEnum.Err_203,"单位编号为空");
        }
        if (setDeviceStatusBySaasVo.getStatus() == null){
            log.error("状态为空");
            return ResultUtil.error(ResultEnum.Err_203,"状态为空");
        }
        return accessDeviceService.SetDeviceActBySaas(setDeviceStatusBySaasVo);
    }

    //SaaS平台注销设备（SetDeviceUnActBySaas）
    @PostMapping(AiotUrl.Url_SetDeviceUnActBySaas)
    public Result SetDeviceUnActBySaas(@Validated  @RequestBody SetDeviceStatusBySaasVo setDeviceStatusBySaasVo){
        if (setDeviceStatusBySaasVo.getDeviceNo().isEmpty() ){
            log.error("设备编号为空");
            return ResultUtil.error(ResultEnum.Err_203,"设备编号为空");
        }
        if ( setDeviceStatusBySaasVo.getSaasNo().isEmpty()){
            log.error("SaaS平台编号为空");
            return ResultUtil.error(ResultEnum.Err_203,"SaaS平台编号");
        }
        if (setDeviceStatusBySaasVo.getComId() == null){
            log.error("单位编号为空");
            return ResultUtil.error(ResultEnum.Err_203,"单位编号为空");
        }
        return accessDeviceService.SetDeviceUnActBySaas(setDeviceStatusBySaasVo);
    }
}
